package com.village.friend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.village.friend.constant.PayStatus;
import com.village.friend.dto.request.UserOrderQueryDto;
import com.village.friend.entity.UserOrder;
import com.village.friend.mapper.UserOrderMapper;
import com.village.friend.service.UserOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 交易订单 服务实现类
 * </p>
 *
 * @author yl
 * @since 2021-08-23
 */
@Service
public class UserOrderServiceImpl extends ServiceImpl<UserOrderMapper, UserOrder> implements UserOrderService {

    @Override
    public List<UserOrder> listByStatus(PayStatus status) {
        QueryWrapper<UserOrder> qw = new QueryWrapper<>();
        qw.eq("pay_status",status.getValue());
        qw.ge("create_time", LocalDateTime.now().minusDays(20));
        qw.orderByDesc("create_time");
        return list(qw);
    }

    @Override
    public IPage<UserOrder> pageByParam(Integer pageCount,Integer limit,Integer parent) {
        IPage<UserOrder> page = new Page<>(pageCount,limit );
        QueryWrapper<UserOrder> qw = new QueryWrapper<>();
        qw.eq("pay_status","SUCCESS");
        qw.eq("parent",parent);
        qw.orderByDesc("create_time");
        return page(page,qw);
    }
}
